#pragma once
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
#include <msclr\marshal_cppstd.h>
#include "Administrator.h"
#include "Stuff.h"
#include "Student.h"
using namespace std;


namespace Project {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for MyForm
	/// </summary>
	public ref class MyForm : public System::Windows::Forms::Form
	{
	public:
		MyForm(void)
		{
			InitializeComponent();
			Pass->PasswordChar = '*';
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~MyForm()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::TextBox^  User;
	private: System::Windows::Forms::TextBox^  Pass;
	private: System::Windows::Forms::GroupBox^  groupBox1;
	private: System::Windows::Forms::LinkLabel^  linkLabel1;
	private: System::Windows::Forms::LinkLabel^  linkLabel2;


	protected:

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm::typeid));
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->User = (gcnew System::Windows::Forms::TextBox());
			this->Pass = (gcnew System::Windows::Forms::TextBox());
			this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
			this->linkLabel1 = (gcnew System::Windows::Forms::LinkLabel());
			this->linkLabel2 = (gcnew System::Windows::Forms::LinkLabel());
			this->groupBox1->SuspendLayout();
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->BackColor = System::Drawing::Color::Transparent;
			this->button1->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
			this->button1->FlatAppearance->MouseOverBackColor = System::Drawing::Color::Red;
			this->button1->ForeColor = System::Drawing::Color::Black;
			this->button1->Location = System::Drawing::Point(88, 114);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(60, 24);
			this->button1->TabIndex = 0;
			this->button1->Text = L"LOGIN";
			this->button1->UseVisualStyleBackColor = false;
			this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(16, 31);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(55, 13);
			this->label1->TabIndex = 1;
			this->label1->Text = L"Username";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(16, 71);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(53, 13);
			this->label2->TabIndex = 2;
			this->label2->Text = L"Password";
			// 
			// User
			// 
			this->User->Location = System::Drawing::Point(88, 28);
			this->User->Name = L"User";
			this->User->Size = System::Drawing::Size(100, 20);
			this->User->TabIndex = 3;
			this->User->Text = L"35";
			// 
			// Pass
			// 
			this->Pass->Location = System::Drawing::Point(88, 71);
			this->Pass->Name = L"Pass";
			this->Pass->Size = System::Drawing::Size(100, 20);
			this->Pass->TabIndex = 4;
			this->Pass->Text = L"35";
			// 
			// groupBox1
			// 
			this->groupBox1->BackColor = System::Drawing::Color::Transparent;
			this->groupBox1->Controls->Add(this->Pass);
			this->groupBox1->Controls->Add(this->button1);
			this->groupBox1->Controls->Add(this->User);
			this->groupBox1->Controls->Add(this->label1);
			this->groupBox1->Controls->Add(this->label2);
			this->groupBox1->Location = System::Drawing::Point(172, 62);
			this->groupBox1->Name = L"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(205, 144);
			this->groupBox1->TabIndex = 5;
			this->groupBox1->TabStop = false;
			this->groupBox1->Text = L"Login";
			// 
			// linkLabel1
			// 
			this->linkLabel1->ActiveLinkColor = System::Drawing::Color::Transparent;
			this->linkLabel1->AutoSize = true;
			this->linkLabel1->BackColor = System::Drawing::Color::Transparent;
			this->linkLabel1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
				static_cast<System::Byte>(0)));
			this->linkLabel1->ForeColor = System::Drawing::Color::Transparent;
			this->linkLabel1->LinkColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(0)), static_cast<System::Int32>(static_cast<System::Byte>(64)),
				static_cast<System::Int32>(static_cast<System::Byte>(0)));
			this->linkLabel1->Location = System::Drawing::Point(50, 290);
			this->linkLabel1->Name = L"linkLabel1";
			this->linkLabel1->Size = System::Drawing::Size(147, 20);
			this->linkLabel1->TabIndex = 6;
			this->linkLabel1->TabStop = true;
			this->linkLabel1->Text = L"Apply (for students)";
			this->linkLabel1->LinkClicked += gcnew System::Windows::Forms::LinkLabelLinkClickedEventHandler(this, &MyForm::linkLabel1_LinkClicked);
			// 
			// linkLabel2
			// 
			this->linkLabel2->ActiveLinkColor = System::Drawing::Color::Transparent;
			this->linkLabel2->AutoSize = true;
			this->linkLabel2->BackColor = System::Drawing::Color::Transparent;
			this->linkLabel2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
				static_cast<System::Byte>(0)));
			this->linkLabel2->LinkColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(0)), static_cast<System::Int32>(static_cast<System::Byte>(64)),
				static_cast<System::Int32>(static_cast<System::Byte>(0)));
			this->linkLabel2->Location = System::Drawing::Point(397, 290);
			this->linkLabel2->Name = L"linkLabel2";
			this->linkLabel2->Size = System::Drawing::Size(136, 20);
			this->linkLabel2->TabIndex = 7;
			this->linkLabel2->TabStop = true;
			this->linkLabel2->Text = L"Apply ( for Staffs )";
			this->linkLabel2->LinkClicked += gcnew System::Windows::Forms::LinkLabelLinkClickedEventHandler(this, &MyForm::linkLabel2_LinkClicked);
			// 
			// MyForm
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"$this.BackgroundImage")));
			this->ClientSize = System::Drawing::Size(659, 441);
			this->Controls->Add(this->linkLabel2);
			this->Controls->Add(this->linkLabel1);
			this->Controls->Add(this->groupBox1);
			this->Name = L"MyForm";
			this->Text = L"Login Page";
			this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
			this->groupBox1->ResumeLayout(false);
			this->groupBox1->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 try{
					 if (User->Text->Length == 0 || Pass->Text->Length == 0) throw 0;
					 else {

						 int a = System::Convert::ToInt32(User->Text);
						 int b = System::Convert::ToInt32(Pass->Text);

						 msclr::interop::marshal_context context;
						 string user_name = context.marshal_as<string>(User->Text);
						 string pass_word = context.marshal_as<string>(Pass->Text);

						 ifstream afile("AdministratorPass.txt");

						 char  line[100];
						 int c, d;

						 if (afile.is_open())
						 {
							 while (afile>>line)
							 {
								 c = atoi(line);
								 afile >> line;
								 d = atoi(line);
								 
								 
								 if (c == a  && b == d){
									 throw 1;
								 }
							 }
						 }
						 afile.close();

						 ifstream sfile("StudentPass.txt");

						 if (sfile.is_open())
						 {
							 while (sfile >> line)
							 {
								 c = atoi(line);
								 sfile >> line;
								 d = atoi(line);


								 if (c == a  && b == d){
									 throw 2;
								 }
							 }
						 }
						 sfile.close();

						 ifstream stfile("StaffPass.txt");


						 if (stfile.is_open())
						 {
							 while (stfile >> line)
							 {
								 c = atoi(line);
								 stfile >> line;
								 d = atoi(line);


								 if (c == a  && b == d){
									 throw 3;
								 }
							 }
						 }
						 stfile.close();
			
					 }
				 }
				 catch (int x){
					 if (!x) MessageBox::Show("Invalid");
					 else{
						 this->Hide();
						 Administrator^ form1000 = gcnew Administrator();
						 Student^ form1 = gcnew Student();
						 Stuff^ form2 = gcnew Stuff();
						 if (x == 1)form1000->ShowDialog();
						 if (x == 2)form1->ShowDialog();
						 if (x == 3)form2->ShowDialog();
					 }
				 }
	}
private: System::Void linkLabel1_LinkClicked(System::Object^  sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^  e) {
			 this->Hide();
			 Student^ form8 = gcnew Student();
			 form8->ShowDialog();
}
private: System::Void linkLabel2_LinkClicked(System::Object^  sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^  e) {
			 this->Hide();
			 Stuff^ form9 = gcnew Stuff();
			 form9->ShowDialog();
}
private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
}
};
}
